interface Admin {
  name: String;
  privileges: string[];
}

interface Employee {
  name: String;
  startDate: Date;
}

type UnknownEmployee = Employee | Admin;

function printEmployeeInformation(emp: UnknownEmployee) {
  console.log("Name: " + emp.name);
  // in 关键字用于判断一个对象是否包含一个属性

  // 例如，这里是在判断，emp是否包含“privilege”属性

  // 如果不进行类型保护，emp将 拒绝 对“可能存在的”属性的保护
  // 换言之，ts只允许访问一定存在的属性
  if ("privileges" in emp) {
    console.log("Privilege:", emp.privileges);
  }
  if ("startDate" in emp) {
    console.log("Start Date:", emp.startDate);
  }
}

let a: Employee;
a.name = "a";
a.startDate = new Date();

printEmployeeInformation(a);
